
package com.kugou.game.sdk.ui.widget;

import com.kugou.game.sdk.utils.Rx;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class TouchToChangeLinearLayout extends LinearLayout {

    public TouchToChangeLinearLayout(Context context) {
        super(context);
    }

    public TouchToChangeLinearLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public void focusView() {
        TextView tvTitle = (TextView) findViewWithTag("title");
        TextView tvContent = (TextView) findViewWithTag("content");
        ImageView ivIconMore = (ImageView) findViewWithTag("more");
        ImageView ivEditIconMore = (ImageView) findViewWithTag("editmore");

        if (tvTitle != null) {
            tvTitle.setTextColor(this.getResources().getColor(android.R.color.white));
        }
        if (tvContent != null) {
            tvContent.setTextColor(this.getResources().getColor(android.R.color.white));
        }
        if (ivIconMore != null) {
            ivIconMore.setImageResource(Rx.drawable.kg_common_button_photo);
        }
        if (ivEditIconMore != null) {
            ivEditIconMore.setImageResource(Rx.drawable.kg_common_button_photo);
        }
        setBackgroundDrawable(getResources().getDrawable(

        Rx.drawable.kg_common_button_background_pressed));
    }

    public void resumeView(int action) {

        TextView tvTitle = (TextView) findViewWithTag("title");
        TextView tvContent = (TextView) findViewWithTag("content");
        ImageView ivIconMore = (ImageView) findViewWithTag("more");
        ImageView ivEditIconMore = (ImageView) findViewWithTag("editmore");

        if (tvTitle != null) {
            tvTitle.setTextColor(this.getResources().getColor(android.R.color.black));
        }
        if (tvContent != null) {
            tvContent.setTextColor(this.getResources().getColor(android.R.color.black));
        }
        if (ivIconMore != null) {
            ivIconMore.setImageResource(Rx.drawable.kg_common_button_photo_pressed);
        }
        if (ivEditIconMore != null) {
            ivEditIconMore.setImageResource(Rx.drawable.kg_common_button_photo_pressed);
        }
        // setBackgroundDrawable(getResources().getDrawable(
        // ResIdManager.getColorId(getContext(),
        // Rx.color.kg_common_background)));
        setBackgroundResource(Rx.color.kg_common_background);

    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        int pointCount = ev.getPointerCount();
        if (pointCount == 1) {
            int action = ev.getAction();
            switch (action) {
                case MotionEvent.ACTION_MOVE:
                case MotionEvent.ACTION_DOWN:
                    focusView();
                    break;

                case MotionEvent.ACTION_UP:
                    resumeView(MotionEvent.ACTION_UP);
                    break;
                case MotionEvent.ACTION_CANCEL:
                    resumeView(MotionEvent.ACTION_CANCEL);
                    break;
            }
            return true;

        } else {
            return false;
        }

    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        int action = ev.getAction();
        switch (action) {
            case MotionEvent.ACTION_DOWN:
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                break;
            case MotionEvent.ACTION_CANCEL:
                break;
        }
        return super.dispatchTouchEvent(ev);
    }

}
